#common makefile header

# 设置目标架构，默认为arm
ARCH ?= arm

# 设置交叉编译工具链路径
TOOLCHAIN_DIR ?= /opt/atk-dlrv1126-toolchain
SYSROOT ?= $(TOOLCHAIN_DIR)/arm-buildroot-linux-gnueabihf/sysroot

# 设置目录和工具链
DIR_INC = ../include
DIR_BIN = ../bin
DIR_LIB = ../libs

# 设置交叉编译工具链
CROSS_COMPILE = $(TOOLCHAIN_DIR)/usr/bin/arm-linux-gnueabihf-

# 添加sysroot支持
SYSROOT_CFLAGS = --sysroot=$(SYSROOT)

TARGET = ivw_sample
BIN_TARGET = $(DIR_BIN)/$(TARGET)

# 基础编译选项
BASE_CFLAGS = -g -Wall -I$(DIR_INC) $(SYSROOT_CFLAGS)
BASE_CPPFLAGS = -std=c++11 $(BASE_CFLAGS)

# 应用特定选项
CFLAGS = $(BASE_CFLAGS) -Wno-format -Wno-unused-function
CPPFLAGS = $(BASE_CPPFLAGS)
LDFLAGS = -L$(DIR_LIB) $(SYSROOT_CFLAGS) -laikit -lrt -ldl -lpthread -lasound

# 源文件处理
COBJECTS := $(patsubst %.c,%.o,$(wildcard *.c))
CPPOBJECTS := $(patsubst %.cpp,%.o,$(wildcard *.cpp))

$(BIN_TARGET): $(COBJECTS) $(CPPOBJECTS)
	$(CROSS_COMPILE)g++ $(CPPFLAGS) $^ -o $@ $(LDFLAGS)

%.o: %.c
	$(CROSS_COMPILE)gcc -c $(CFLAGS) $< -o $@

%.o: %.cpp
	$(CROSS_COMPILE)g++ -c $(CPPFLAGS) $< -o $@

clean:
	@rm -f *.o $(BIN_TARGET)

.PHONY: clean

#common makefile foot